import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn, Index } from 'typeorm';

@Entity('menus')
@Index(['parentId', 'orderNum'])
export class Menu {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 50, comment: '菜单名称' })
  name: string;

  @Column({ length: 200, comment: '路由路径' })
  path: string;

  @Column({ length: 200, nullable: true, comment: '组件路径' })
  component: string;

  @Column({ length: 50, nullable: true, comment: '图标' })
  icon: string;

  @Column({ name: 'parent_id', default: 0, comment: '父级ID' })
  parentId: number;

  @Column({ name: 'order_num', default: 0, comment: '排序号' })
  orderNum: number;

  @Column({ default: 1, comment: '状态(0:禁用,1:启用)' })
  status: number;

  @Column({ length: 100, nullable: true, comment: '权限标识' })
  permission: string;

  @Column({ comment: '类型(0:目录,1:菜单,2:按钮)' })
  type: number;

  @CreateDateColumn({ name: 'create_time' })
  createTime: Date;

  @UpdateDateColumn({ name: 'update_time' })
  updateTime: Date;
  
  // 子菜单
  children?: Menu[];
}